<template>
  <el-dialog title="新增机柜" v-model="dialogVisible">
    <el-form :model="formData" :rules="rules" ref="formRef">
      <el-form-item label="机柜名称" prop="name">
        <el-input type="textarea" v-model="formData.name" show-word-limit maxlength="200" placeholder="请输入机柜名称" />
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="handleAdd(formRef)">确认 </el-button>
      </span>
    </template>
  </el-dialog>
</template>
<script setup>
import { ref } from "vue";
import { Picture } from "@element-plus/icons-vue";
import { async } from "@antv/x6/lib/registry/marker/async";
const dialogVisible = ref(false);
const formRef = ref();
const formData = ref({
  name: "",
});
const rules = {
  name: [{ required: true, message: "请输入机柜名称", trigger: "blur" }],
};
const handleAdd = async (formEl) => {
  if (!formEl) return;
  await formEl.validate(async (valid, fields) => {
    if (valid) {
      dialogVisible.value = false;
    }
  });
};

const handleOpen = () => {
  dialogVisible.value = true;
};

const handleClose = () => {
  dialogVisible.value = false;
};
defineExpose({
  handleOpen,
  handleClose,
});
</script>
<style lang="scss" scoped>
::v-deep .el-textarea textarea {
  height: 100px;
}
</style>